home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / com_and3.zip / MDMDIAG.CMD < prev    next >
OS/2 REXX Batch file  |  1990-10-04  |  7KB  |  232 lines

  1.         ON ESCAPE GOSUB Exit
  2.         LEGEND " Modem diagnostic"
  3. ;***    TRACE ON
  4. ;
  5. ; ----- MdmDiag: Modem diagnostic routine for COM-AND.
  6. ;
  7. ;       R.McG; 8/90, Chicago
  8. ; ----------------------------------------------------------------
  9. ;       Usages:
  10. ;          S0 carries the original port/speed when entered
  11. ;          N99,N98 contain original cursor row, col
  12. ; ----------------------------------------------------------------
  13. ;
  14. ;       Initialization..
  15. ;
  16.         SAVE 0,0,"_SSIZE"-1,79          ; Save original screen
  17.         CURSOR N99,N98
  18.         CLEAR                           ; Clear screen
  19.         COMPARMS S0                     ; Get current settings
  20.         S0 = S0(11:14)                  ; Make it easy
  21. ;
  22. ;       Find the port to use, and take register values
  23. ;
  24.         GOSUB TestPort                  ; Find which ports exist
  25.         GOSUB GetPort                   ; Set port name we'll use (into S1)
  26.         SET PORT S1                     ; Switch to desired port
  27.         COMBASE S1 N0                   ; Get port base addr from str in s1
  28.         GOSUB GetRegs                   ; Using N0, rtn N1-N7 values
  29. ;
  30. ;       Display the port/base addr
  31. ;
  32.         BOX   0,0,3,38 (default)
  33.         ATSAY 1,2 (default) "Comm setting: "*"_PARM"
  34.         STRFMT S2 "%x" N0
  35.         ATSAY 2,2 (default) "Base address: "*S2
  36.         COMVEC S1 N0
  37.         ATSAY 2,25 (default) "IRQ: "*N0
  38. ;
  39. ;       Display the LCR
  40. ;
  41.         S1 = " Line Control Register "
  42.         S2 = "DLB STB STP EPS PEN STB WS1 WS0"
  43.         N8 = 40
  44.         N9 = 0
  45.         N0 = N1
  46.         GOSUB DISPREG
  47. ;
  48. ;       Display the LSR
  49. ;
  50.         S1 = " Line Status Register "
  51.         S2 = "    TSE THE BI  FE  PE  OE  DR "
  52.         N9 = 4
  53.         N0 = N2
  54.         GOSUB DISPREG
  55. ;
  56. ;       Display the MCR
  57. ;
  58.         S1 = " Modem Control Register "
  59.         S2 = "            LP  OT2 OT1 RTS DTR"
  60.         N9 = 8
  61.         N0 = N3
  62.         GOSUB DISPREG
  63. ;
  64. ;       Display the MSR
  65. ;
  66.         S1 = " Modem Status Register "
  67.         S2 = "RLS RI  DSR CTS DRD TER DDR DCS"
  68.         N9 = 12
  69.         N0 = N4
  70.         GOSUB DISPREG
  71. ;
  72. ;       Display the IIR
  73. ;
  74.         S1 = " Interrupt ID Register "
  75.         S2 = "                    ID2 ID1 ITP"
  76.         N9 = 16
  77.         N0 = N5
  78.         GOSUB DISPREG
  79. ;
  80. ;       Display the IER
  81. ;
  82.         S1 = " Interrupt Enable Register "
  83.         S2 = "                ESI ELI ETI ERI"
  84.         N9 = 20
  85.         N0 = N6
  86.         GOSUB DISPREG
  87. ;
  88. ;       Display the IMR
  89. ;
  90.         S1 = " Interrupt Mask Register "
  91.         S2 = "IQ7 IQ6 IQ5 IQ4 IQ3 IQ2 IQ1 IQ0"
  92.         N8 = 0
  93.         N9 = 4
  94.         N0 = N7
  95.         GOSUB DISPREG
  96. ;
  97. ;       Wait for a Keypress
  98. ;
  99.         LEGEND " Modem Diagnostic - press any key to quit"
  100.         KEYGET S1
  101. ;
  102. ;       And we're done
  103. ;
  104. Exit:
  105.         SET PORT S0             ; Restore original port
  106.         DO                      ; There may be multiple saves outstanding
  107.            RESTORE              ; .. restore all
  108.            UNTIL FAILURE
  109.         LOCATE N99,N98
  110.         EXIT
  111. ;
  112. ; ----- Display a register's value
  113. ;          S1  passed -> Legend for Box
  114. ;          S2  passed -> 1st line of box display (we'll draw 2nd)
  115. ;          N0  passed -> Register value
  116. ;          N9  passed -> Row number of top of box
  117. ;          N8  passed -> Col number of topleft of box
  118. ;
  119. DISPREG:
  120.         BOX   N9,N8,N9+3,N8+38 (default)
  121.         ATSAY N9+1,N8+2 (default) S2
  122.         ATSAY N9,N8+2 (default) S1
  123.         N10 = 128
  124.         N11 = 1
  125.         S3 = ""
  126.         WHILE N10 GT 0
  127.               IF 0 NE (N0 & N10) S3(N11:N11) = "1"
  128.               N10 = N10/2
  129.               N11 = N11+4
  130.               ENDWHILE
  131.         ATSAY N9+2,N8+2 (default) S3
  132.         RETURN
  133. ;
  134. ; ----- Get register values
  135. ;          N0  passed -> Base address for port
  136. ;          N1-N7 returned: register values
  137. ;
  138. GetRegs:
  139.         INPUT N1,N0+3           ; Line control reg
  140.         INPUT N2,N0+5           ; Line status reg
  141.         INPUT N3,N0+4           ; Modem control reg
  142.         INPUT N4,N0+6           ; Modem status reg
  143.         INPUT N5,N0+2           ; Interrupt ID reg
  144.         INPUT N6,N0+1           ; Interrupt enable
  145.         INPUT N7,0x21           ; Interrupt make register (8259)
  146.         RETURN
  147. ;
  148. ; ----- Get Port name to use
  149. ;          S0  passed default port name
  150. ;          S1  returned: port name to be used
  151. ;
  152. GetPort:
  153.         WOPEN 10,10,17,50 (default)
  154.         ATSAY 10,12 (default) " Modem Diag Select "
  155.         IF FLAG(0) ATSAY 11,12 (default) "1) Select COM1"
  156.         IF FLAG(1) ATSAY 12,12 (default) "2) Select COM2"
  157.         IF FLAG(2) ATSAY 13,12 (default) "3) Select COM3"
  158.         IF FLAG(3) ATSAY 14,12 (default) "4) Select COM4"
  159.         ATSAY 15,12 (default)            "5) Use default (also c/r)"
  160.         ATSAY 16,12 (default)            "Select from above: "
  161.         ATSAY 17,20 (default) " Press ESC to exit "
  162.         LOCATE 16,32
  163.         KEYGET S1
  164.         SWITCH S1
  165.                CASE "1"
  166.                     S1 = "COM1"
  167.                     ENDCASE
  168.                CASE "2"
  169.                     S1 = "COM2"
  170.                     ENDCASE
  171.                CASE "3"
  172.                     S1 = "COM3"
  173.                     ENDCASE
  174.                CASE "4"
  175.                     S1 = "COM4"
  176.                     ENDCASE
  177.                CASE "5"                 ; Default case
  178.                     S1 = S0             ; .. use it
  179.                     ENDCASE
  180.                CASE "0D"                ; Default case
  181.                     S1 = S0             ; .. use it
  182.                     ENDCASE
  183.                DEFAULT
  184.                     SOUND 100,100
  185.                     WCLOSE              ; We'll reopen above
  186.                     GOTO GetPort        ; .. try again
  187.                     ENDCASE
  188.                ENDSWITCH
  189.         WCLOSE
  190.         RETURN
  191. ;
  192. ; ----- Test existing ports...
  193. ;          S0 passed is the default port
  194. ;          FLAGS 0-3 are returned t/f according to the corresponding
  195. ;          port's existance
  196. ;
  197. TestPort:
  198.         SET FLAG(0) OFF
  199.         SET FLAG(1) OFF
  200.         SET FLAG(2) OFF
  201.         SET FLAG(3) OFF
  202.         SET PORT COM1
  203.         IF "_UART" GE 0 SET FLAG(0) ON
  204.         SET PORT COM2
  205.         IF "_UART" GE 0 SET FLAG(1) ON
  206.         SET PORT COM3
  207.         IF "_UART" GE 0 SET FLAG(2) ON
  208.         SET PORT COM4
  209.         IF "_UART" GE 0 SET FLAG(3) ON
  210.         SET PORT S0             ; Restore default
  211.         RETURN
  212. ;
  213. ; ----- Subroutine: Fatal error.  Open a window, and display a message
  214. ;       S0 passes the error message(s)
  215. ;
  216. Error:
  217.         WOPEN 10,10,12,70 (contrast) Err_Esc
  218.         ATSAY 10,12 (contrast) " Modem Diag Error "
  219.         ATSAY 11,12 (contrast) S0(0:55); Max msg width 55 chars
  220.         ATSAY 12,26 (contrast) " Press any key to continue "
  221.         ;
  222.         ;    Wait a keypress
  223.         ;
  224.         KEYGET S0                       ; Wait for any key
  225.         WCLOSE
  226.         RETURN
  227.         ;
  228.         ;    Escape during this screen
  229.         ;
  230.      Err_Esc:
  231.         RETURN
  232.